import { _decorator, Sprite, tween, Tween, UITransform } from 'cc';
import { $planet_BaseUI_poof$ } from '../../../frame/component/ui.base';
import $planet_DC_poof$ from '../data/data.center';
const { ccclass, property } = _decorator;

@ccclass('$planet_Home_poof$')
export class $planet_Home_poof$ extends $planet_BaseUI_poof$ {

	private ui_background: UITransform;

	private va_background: abd.$planet_cc_poof$.$planet_VecAssist_poof$;

	protected $planet_initAfterOnLoad_poof$(): void {
		this.$planet_init_poof$();
	}

	private $planet_init_poof$(){
		this.ui_background = this.node.getChildByName('background').getComponent(UITransform);
		this.va_background = new abd.$planet_cc_poof$.$planet_VecAssist_poof$(this.ui_background.node);

		this.$planet_adaptUI_poof$();
	}

	private $planet_adaptUI_poof$(){
		let size = this.ui_background.getComponent(Sprite).spriteFrame.originalSize;
		let ratio = abd.$planet_size_poof$.$planet_exterRatio_poof$(size, abd.$planet_size_poof$.$planet_canvasSize_poof$);
		this.ui_background.setContentSize(size.width * ratio, size.height * ratio);

		this.ui_background.node.setPosition(this.va_background.$planet_getPosition_poof$('$planet_left_poof$', '$planet_center_poof$'));
	}

	protected $planet_listening_poof$(){
		let list = [];

		Promise.all([
			$planet_DC_poof$.$planet_follow_poof$('$planet_trigger_poof$', '$planet_UI_HOME_poof$', (o, show)=>{
				if(show===o) return void 0;
				show ? this.$planet_enter_poof$() : this.$planet_leave_poof$();
			}, false),
		]).then(ls=>list.push(...ls));

		return list;
	}

	private $planet_enter_poof$(){
		let duration = 0.5;
		let np = new abd.$planet_NudityPromise_poof$<0>();
		this.node.active = true;
		this.scheduleOnce(()=>np.$planet_resolve_poof$(0), duration+0.05);

		Tween.stopAllByTarget(this.ui_background.node);
		tween(this.ui_background.node)
		.to(duration, {position: this.va_background.$planet_getPosition_poof$('$planet_left_poof$', '$planet_center_poof$')})
		.start();

		return np.$planet_promise_poof$;
	}

	private $planet_leave_poof$(){
		let duration = 0.5;
		let np = new abd.$planet_NudityPromise_poof$<0>();
		this.scheduleOnce(()=>np.$planet_resolve_poof$(0), duration+0.05);

		Tween.stopAllByTarget(this.ui_background.node);
		tween(this.ui_background.node)
		.to(duration, {position: this.va_background.$planet_getPosition_poof$('$planet_over_left_poof$', '$planet_center_poof$')})
		.start();

		return np.$planet_promise_poof$;
	}
}

